package com.drama.api.sys.withdraw.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.drama.api.base.ApiIndex;
import com.drama.api.base.Constants;
import com.drama.api.base.R;
import com.drama.api.base.RestPage;
import com.drama.api.sys.withdraw.domain.vo.SysCompanyWithdrawUpdateVO;
import com.drama.api.sys.withdraw.domain.vo.SysCompanyWithdrawCountVO;
import com.drama.api.sys.withdraw.domain.vo.SysCompanyWithdrawSearchVO;
import com.drama.api.sys.withdraw.domain.vo.SysCompanyWithdrawVO;
import com.drama.api.sys.withdraw.service.ISysCompanyWithdrawService;
import com.drama.util.BindingResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@Api( tags = ApiIndex.SysCompanyWithdrawController)
@RequestMapping(value = "/api/sys/withdraw")
@RestController
@SaCheckLogin
public class SysCompanyWithdrawController {

    @Autowired
    private ISysCompanyWithdrawService service;

    @ApiOperation(value = "查询商户提现列表")
    @GetMapping(value = "/list")
    public R<RestPage<List<SysCompanyWithdrawVO>>> list(
            @ApiParam(value = "查询参数") @ModelAttribute SysCompanyWithdrawSearchVO searchVO) {
        List<SysCompanyWithdrawVO> list = service.getList(searchVO);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }

    @ApiOperation(value = "查询提现统计")
    @GetMapping(value = "/get_count")
    public R<SysCompanyWithdrawCountVO> get_count() {
        SysCompanyWithdrawCountVO vo = service.get_count();
        return new R(vo);
    }

    @ApiOperation(value = "完成商户提现")
    @PostMapping(value = "/complete")
    public R complete(@ApiParam(value = "添加参数") @Valid @RequestBody SysCompanyWithdrawUpdateVO vo, BindingResult bindingResult) {
        R result= BindingResultUtil.BindingResult(bindingResult);
        if(result.getCode()== Constants.SYS_SUCCESS){
            service.complete(vo);
        }
        return result;
    }

}
